package dao

import (
	"golang.org/x/net/context"
	"sale-admin/internal/dal"
)

type IMaGoodsInfoFilter interface {
	fmtFilter(ctx context.Context, tx dal.IMaGoodsInfoDo, q *dal.Query) dal.IMaGoodsInfoDo
}

var _ IMaGoodsInfoFilter = (*MaGoodsInfoFilter)(nil)

type MaGoodsInfoFilter struct {
	ID      string
	GoodsID string
}

// 筛选器
func (p *MaGoodsInfoFilter) fmtFilter(ctx context.Context, tx dal.IMaGoodsInfoDo, q *dal.Query) dal.IMaGoodsInfoDo {
	if p.ID != "" {
		tx = tx.Where(q.MaGoodsInfo.ID.Eq(p.ID))
	}

	if p.GoodsID != "" {
		tx = tx.Where(q.MaGoodsInfo.GoodsID.Eq(p.GoodsID))
	}

	return tx
}

type MaGoodsInfoListFilter struct {
	ID      string
	Deleted *int
}

func (p *MaGoodsInfoListFilter) fmtFilter(ctx context.Context, tx dal.IMaGoodsInfoDo, q *dal.Query) dal.IMaGoodsInfoDo {
	if p.ID != "" {
		tx = tx.Where(q.MaGoodsInfo.ID.Eq(p.ID))
	}

	if p.Deleted != nil {
		tx = tx.Where(q.MaGoodsInfo.Deleted.Eq(*p.Deleted))
	} else {
		//默认只查询未被删除的
		tx = tx.Where(q.MaGoodsInfo.Deleted.Eq(0))
	}

	return tx
}
